libobs_simple\sources\linux\sources/
v4l2_input.rs

1use libobs_wrapper::{
2    data::StringEnum,
3    sources::{ObsSourceBuilder, ObsSourceRef},
4};
5use num_derive::{FromPrimitive, ToPrimitive};
6
7use crate::sources::macro_helper::define_object_manager;
8
9#[repr(i64)]
10#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
11/// Video color range for V4L2 input
12pub enum ObsV4L2ColorRange {
13    /// Default color range
14    Default = 0,
15    /// Partial color range (limited)
16    Partial = 1,
17    /// Full color range
18    Full = 2,
19}
20
21impl StringEnum for ObsV4L2ColorRange {
22    fn to_str(&self) -> &str {
23        match self {
24            ObsV4L2ColorRange::Default => "Default",
25            ObsV4L2ColorRange::Partial => "Partial",
26            ObsV4L2ColorRange::Full => "Full",
27        }
28    }
29}
30
31define_object_manager!(
32    #[derive(Debug)]
33    /// A source for Video4Linux2 (V4L2) camera input.
34    ///
35    /// This source captures video from V4L2 compatible devices such as webcams,
36    /// capture cards, and other video input devices on Linux.
37    struct V4L2InputSource("v4l2_input") for ObsSourceRef {
38        /// Device ID/path (e.g., "/dev/video0")
39        #[obs_property(type_t = "string")]
40        device_id: String,
41
42        /// Input number on the device
43        #[obs_property(type_t = "int")]
44        input: i64,
45
46        /// Pixel format (FOURCC code as integer)
47        #[obs_property(type_t = "int")]
48        pixelformat: i64,
49
50        /// Video standard for analog inputs
51        #[obs_property(type_t = "int")]
52        standard: i64,
53
54        /// DV timing for digital inputs
55        #[obs_property(type_t = "int")]
56        dv_timing: i64,
57
58        #[obs_property(type_t = "int")]
59        resolution: i64,
60
61        #[obs_property(type_t = "int")]
62        framerate: i64,
63
64        /// Color range setting
65        #[obs_property(type_t = "int")]
66        color_range: i64,
67
68        /// Auto-reset on timeout
69        #[obs_property(type_t = "bool")]
70        auto_reset: bool,
71
72        /// Frames until timeout
73        #[obs_property(type_t = "int")]
74        timeout_frames: i64,
75    }
76);
77
78impl V4L2InputSourceBuilder {
79    /// Set the color range using the enum
80    pub fn set_color_range_enum(self, color_range: ObsV4L2ColorRange) -> Self {
81        use num_traits::ToPrimitive;
82        self.set_color_range(color_range.to_i64().unwrap())
83    }
84}
85
86impl ObsSourceBuilder for V4L2InputSourceBuilder {}